<template>
  <div id="member-transfer-integral">
    <c-title :text="`${point_name}转提现积分`"></c-title>
    <div class="main">
      <p class="current_integral">当前{{point_name}}：{{point}}</p>
      <div class="popup">
        <p class="left f-13">{{point_name}}转提现积分</p>
        <van-field v-model="transfer_point" placeholder="0.00" />
        <div class="line"></div>
        <div class="btn">
          <van-button  :disabled="loading" :loading="loading" block color="#F24E4E" @click="submitSjh">确认转化</van-button>
          <div style="margin-top: 20px;">可提现积分: {{ ketixian_sjh }}</div>
          <div>已提现积分: {{ yitixian_sjh }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      toi: this.fun.getKeyByI(),
      text: "",
      transfer_point: '',
      loading:false,
      credit1: "",
      point_name: "团拼奖",
      integral_name: "",
      transfer_integral_ratio: 0,
      loveByMember:0, //是否开启积分手动转爱心值
      transfer_integral:0, //积分
      transfer_integral_love:0, //爱心值
      exchange_num:0, //转换的积分
      love:'',
      ketixian_sjh: 0,//十佳合--团拼奖励可提现积分
      yitixian_sjh: 0,//十佳合--团拼奖励已提现积分
      menkan_sjh: 0,//十佳合--团拼奖励提现积分门槛
      point_sjh: 0,//十佳合--团拼奖励积分,
      uniacid: '',//平台标识
      point: 0, //团拼奖
    };
  },
  computed:{
    practical_num(){
      if(this.transfer_point>0){
        let res = 0,
          value = 0;
        if(this.loveByMember) {
          res = this.transfer_integral_love/this.transfer_integral;
          value = res.toFixed(4) * this.transfer_point;
        } else {
          res = this.transfer_integral_ratio/this.transfer_integral;
          value = res.toFixed(4) * this.transfer_point;
        }
        return value.toFixed(2);
      }else{
        return 0;
      }
    }
  },
  mounted() {
    let basic_info = JSON.parse(localStorage.getItem("yz_basic_info"));
    this.love = basic_info.love;
    let query = this.$route.query;
    let {loveByMember} = {...query};
    this.loveByMember = Number(loveByMember);
    // console.log(this.loveByMember);
    // if(loveByMember){
    //   this.getLoveData();
    // }else{
    //   this.getData();
    // }
    this.uniacid = this.$route.query.i;
    this.getData();
    // this.point = this.$route.params.point ? this.$route.params.point : window.localStorage.getItem('tuanpin_point');
    this.getTixianDate();
  },
  methods: {
    // 十佳合--团拼奖励查看提现上限
    getTixianDate(){
      console.log('走了么')
       $http.post("shijiahe.tuanpin_jiang",{
        uid: window.localStorage.getItem('uid') ? window.localStorage.getItem('uid') : '',
       }).then(res => {
        if (res.result == 1) {
          console.log(res,'tuanpin_jiang');
          this.ketixian_sjh = res.data.ketixian;
          this.yitixian_sjh = res.data.yitixian * -1;
          this.menkan_sjh = res.data.menkan;
          this.point_sjh = res.data.point;
          console.log(this.ketixian_sjh,'this.ketixian_sjh');
        }
      });
    },
    getData() {
       var that = this;
        $http.post("shijiahe.my_asset", { 
            uid: localStorage.getItem("uid") ? localStorage.getItem("uid") : localStorage.getItem("mid")
        }).then(res => {
            if (res.result == 1) {
                var obj = res.data;
                console.log(res.data,'我的资产')
                that.point = obj.tuanpin ? obj.tuanpin : 0;//团拼
            }
            
        });
    },
    getLoveData() {
      $http
        .get(
          "finance.point-page.index",
          {
            i: this.fun.getKeyByI(),
            type: this.fun.getTyep()
          },
          "加载中"
        )
        .then(
          (response) => {
            if (response.result == 1) {
              console.log(response.data);
              this.credit1 = response.data.credit1;
              this.transfer = response.data.transfer;
              this.lan_name = response.data.lan_name;
              this.transfer_integral = response.data.transfer_integral;
              this.transfer_integral_love = response.data.transfer_integral_love;
            } else {
              this.$dialog.alert({ message: response.msg });

            }
          },
          (response) => {
            this.$dialog.alert({ message: response.msg });
          }
        );
    },
   
    // 十佳合体现转化
    submitSjh() {
      if(this.transfer_point > parseFloat(this.point_sjh)){
        this.$toast('转化团拼奖不能大于可用团拼奖');
        return false;
      }
      if(this.transfer_point > parseFloat(parseFloat(this.ketixian_sjh)-parseFloat(this.yitixian_sjh * -1))){
        this.$toast('转化团拼奖不能大于可提现团拼奖');
        return false;
      }
      if(parseFloat(this.point_sjh) < parseFloat(this.menkan_sjh)){
        this.$toast('转化团拼奖不能小于提现门槛');
        return false;
      }
      this.loading = true;
      let params = {
        uid: window.localStorage.getItem('uid') ? window.localStorage.getItem('uid') : '',
        price: this.transfer_point,
      };
      $http.post("shijiahe.tuanpin_zhuan_point",params).then(res => {
        this.loading=false;
        if(res.result){
          this.$toast(res.msg);
          this.transfer_point= 0;
          this.getData();
          setTimeout(() => {
            this.$router.go(-1);
          },1000);
        }else{
          this.$toast(res.msg);
        }
      });
    },
  }
}
</script>
<style lang="scss" scoped>
#member-transfer-integral {
  .btn {
    border-radius: .375rem;
    overflow: hidden;
    margin-top: 1.5625rem;
  }

  .main {
    position: relative;
    height: 7.5rem;
    padding: 0 .5938rem;
    background: linear-gradient(#FFC11E, #FFC222, #FADC8C, #F9E6B5);
  }

  .popup {
    background: #fff;
    border-radius: 5px;
    position: absolute;
    top: 45%;
    left: .5938rem;
    right: .5938rem;
    padding: 1.2813rem 1.25rem 1.25rem 1.3438rem;
  }

  .left {
    text-align: left;
  }

  .f-13 {
    font-size: .8125rem;
  }

  .current_integral {
    font-size: .875rem;
    color: #333;
    text-align: left;
    padding-top: 0.875rem;
  }

  ::v-deep .van-nav-bar__content {
    background: #FFC11E;
  }

  ::v-deep .van-button--default {
    background: #FFC11E;
  }

  .tips {
    text-align: left;
    font-size: .75rem;

    p {
      margin-top: .375rem;
      margin-bottom: .1875rem;
    }
  }

  .c-9B9B9B {
    color: #9B9B9B;
  }

  .line {
    background: #E7E7E7;
    height: 1px;
    width: 100%;
  }

  ::v-deep .van-cell {
    padding: 10px 0 !important;
  }
}
</style>